# Contributor: Matthias Ahouansou <matthias@ahouansou.cz>
# Maintainer: Matthias Ahouansou <matthias@ahouansou.cz>
pkgname=msh
pkgver=2.5.0
pkgrel=2
pkgdesc="Autostart and stop minecraft-server when players join/leave"
url="https://github.com/gekware/minecraft-server-hibernation"
arch="all"
license="GPL-3.0-only"
makedepends="go"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/gekware/minecraft-server-hibernation/archive/refs/tags/v$pkgver.tar.gz
	msh.initd
	msh.confd
"
builddir="$srcdir/minecraft-server-hibernation-$pkgver"
options="!check" # no tests
pkgusers="$pkgname"
pkggroups="$pkgname"

export GOFLAGS="$GOFLAGS -modcacherw"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go build .
}

package() {
	install -Dm 755 msh "$pkgdir"/usr/bin/msh
	install -dm 644 -o $pkgname -g $pkgname "$pkgdir"/etc/$pkgname # Write access is required

	install -Dm 644 msh-config.json "$pkgdir"/etc/msh/msh-config.json

	install -Dm755 "$srcdir"/msh.initd "$pkgdir"/etc/init.d/msh
	install -Dm644 "$srcdir"/msh.confd "$pkgdir"/etc/conf.d/msh
}

sha512sums="
90b059f8ba7940023a270e4f09b088ca55f319fd4bbfcdc1bca0bc3efd09b2f509074c283640fe4de3124b865060bd9fc1f4805baaafa5017d1bcbfc5c6424b6  msh-2.5.0.tar.gz
c5683294949686b348e5bfb870ff39eed7af64758d7646224335aec7d2c431b0d6cf818b19384e10311e7a381be2c85b052e8d859abe8515ccb7fc514fe4696e  msh.initd
8074464d36b54183f0091e48f2ef25ce0378fc12b0e613a4c53a47a3c8bdd4688b8407f115480d8651ad434cfbfeb681a9beb9650124863843beee97cef259ad  msh.confd
"
